Java (a trademark of Sun Microsystems, Inc.) is an object oriented programming language and execution environment allowing programmers to define software classes as encapsulated software components comprising data and functionality. The functionality within a Java class is represented by software methods which are executed by a Java virtual machine (JVM). A JVM is a virtual computer implemented as software on a computer system. A JVM includes components necessary to load Java classes and execute software methods written in the Java programming language.
Java classes are written by programmers in the Java programming language using Java instructions. Java instructions are subsequently encoded as platform independent bytecodes by a Java compiler and stored in binary Java class files until they are executed. On execution, the JVM loads a Java class file into memory and executes the software methods it contains. To execute a software method the JVM decodes and executes the bytecode instructions for the software method using a Java interpreter. Decoding a bytecode instruction involves converting the byte code instruction into one or more appropriate machine code instructions for the computer platform. The machine code instructions are subsequently executed by the computer's processor. This model of operation ensures Java classes are stored in platform independent bytecode format until execution, and can be loaded and executed on many computer platforms given the presence of a JVM capable of interpreting bytecodes. Java interpretation takes place for a software method each time the software method is executed.
The need to decode Java bytecodes to machine code prior to execution reduces the rate of execution of Java instructions when compared with that of native compiled programs which are stored as machine code (such as a compiled “C” application). Additionally, repeated execution of the same Java software method requires repeated decoding of the software method's bytecodes by the Java interpreter. To improve the speed of execution of Java instructions and reduce duplication through repeatedly decoding the same bytecodes it is desirable to decode the Java bytecodes in advance of execution. Some JVMs facilitate this by decoding all bytecodes in a software method to machine code and storing the machine code in memory when the software method is first executed. Decoding bytecodes for an entire software method in this way also offers the opportunity to optimize the machine code (such as removing non-operations) to further improve the performance of the executing software method. Once all bytecodes are decoded, the machine code is executed. Subsequent execution of the software method results in further execution of the existing machine code in memory. This technique is known as just-in-time (JIT) compilation because decoding takes place “just in time” for the first execution of a software method. JIT compilers result in a higher rate of execution of Java instructions than Java interpreters, though an initial performance penalty is paid as program execution is delayed while bytecodes are decoded to machine code on first execution. The length of the delay caused by JIT compilation is related to the number of bytecodes comprising a software method, with more bytecodes requiring more time for JIT compilation and therefore a longer delay. Furthermore, where a software method is executed few times (e.g. only once) the use of a JIT compiler with optimization can result in slower overall execution than a Java interpreter.
In “Overview of the IBM Java Just-in-Time Compiler” (IBM Systems Journal 2000 Vol. 39, No. 1, pp 175–193) Suganuma et al. disclose a method for executing Java software methods using a combination of a Java interpreter and a JIT compiler. The method involves providing an invocation count for each software method initialized as a certain threshold value. Whenever the software method is executed by the Java interpreter the JVM decrements the invocation count. When the invocation count reaches zero it is determined that the method has been invoked frequently enough and JIT compilation is initiated for the software method. Once JIT compiled the software method is executed in machine code for the remainder of the execution of the program. This technique offers the benefits of JIT compilation to only those software methods whose invocation count exceeds a determined threshold. Before the threshold is exceeded, software methods are executed using a Java interpreter. The use of the threshold to determine appropriate JIT compilation ensures only software methods which are executed frequently will be JIT compiled to justify the investment of processor time in JIT compilation.
In a transactional environment where software methods are executed in a JVM on a computer system in response to transaction requests from one or more client computer systems, multiple software methods are executed in a repetitive fashion over many transactions. This results in the invocation count for multiple software methods meeting the JIT compilation threshold at the same time, and so multiple software methods are JIT compiled at the same time. JIT compilation of multiple software methods results in an increased performance penalty as program execution is delayed while bytecodes are decoded to machine code for each software method. The transaction that caused software methods to exceed the JIT compilation threshold will experience an unacceptably high delay in the JVM processing of the transaction request as multiple software methods are JIT compiled in the JVM.